package com.sc;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Demo4 {

    public static void main(String[] args) {
//        String s = "https://tysl.zwfw.nx.gov.cn/zhsl/police/v1.0/tableDownload?materialId=92784f98ce104c898c6936275ebbc992";
//        String[] s1 = s.split("=");
//        System.out.println(s1[1]);
//        String s = "http://172.31.82.117:8091/haocp/app/downloadApp?deptCode=1164000001006522XG&taskCode=1164000001006522XG2000117004000&taskHandleItem=1164000001006522XG200011700400000&taskName=二级建造师企业名称变更注册&projectNo=64000014180124007&proStatus=3&proDepart=自治区住房和城乡建设厅&pf=3&dataSource=164&flag=zwfw_hcp&acceptDate=2019-08-01 12:30:23";
//        String[] strs = s.split("\\?");
//        System.out.println(strs[1]);

//        while (true) {
//            Scanner s = new Scanner(System.in);
//            String str = s.next();
//            System.out.println(str);
//            boolean str1 = stringFilter(str);
//            System.out.println(str1);
//
//        }

//        String sqlFragment = "insert into t_role(role_id,role_name,"
//                + "role_level,org_id,role_type,role_status,add_user_id,"
//                + "add_time,upd_user_id,upd_time) values(#{id},"
//                + "${role_name},${role_level},${org_id},${role_type},"
//                + "${role_status},"
//                + "#E{accId},#{dateInt},#{accId},#E{dateInt})";
//        Pattern pattern = Pattern.compile("#E\\{[\\w]*\\}");
//        Matcher matcher = pattern.matcher(sqlFragment);
//        //循环，字符串中有多少个符合的，就循环多少次
//        while(matcher.find()){
//            //每一个符合正则的字符串
//            String e = matcher.group();
//            //截取出括号中的内容
//            String substring = e.substring(3, e.length()-1);
//            //字符串截取
//            CharSequence subSequence = sqlFragment.subSequence(matcher.start(0), matcher.end(0));
//            System.out.println("开始位置:"+matcher.start(0)+" 结束位置:"+matcher.end(0));
//            System.out.println(subSequence.toString());
//            System.out.println(e);
//            //进行替换
//            sqlFragment = sqlFragment.replaceAll("\\#E\\{"+substring+"\\}", "123123498496416");
//            //此句代码与上句代码结果一致
////			sqlFragment = sqlFragment.replace(e, "123123");
//
//        }
//        System.out.println(sqlFragment);

//        String str = "2032323200.32.123";
//        //正则表达式
//        String regular = "\\$\\{[a-zA-Z_0-9]*\\}";
//        String regEx = "^([1-9]\\d{0,5}|0)(\\.\\d{1,2})?";
//
//        Pattern p=Pattern.compile(regEx);
//        Matcher m=p.matcher(str);
//        while(m.find()) {
//            m.group();
//            System.out.println(m.group());
//        }

        String balance = "999999.999";
        StringBuilder sb = new StringBuilder(balance);
        if (balance.startsWith(".")) {
            sb.insert(0, "0");
        } else if (balance.contains(".")) {
            String str = sb.toString();
            int pos = str.indexOf(".");
            if (str.length() - pos >= 3) {
                sb.delete(0, sb.length());
                sb.append(balance.substring(0, str.length() - 1));
            }

            sb.delete(0, sb.length());
            sb.append(balance.substring(0, balance.length() - 1));
        }
        float balan = Float.parseFloat(sb.toString());
        if (99999 <= balan) {
            sb.delete(0, sb.length());
            sb.append(balance.substring(0, balance.length() - 1));
        }
        System.out.println(sb.toString());
    }

    public static boolean stringFilter(String str) {
//        // 只允许金额后边两位小数
        String regEx = "^([1-9]\\d{0,5}|0)(\\.\\d{1,2})?";
//        Pattern p = Pattern.compile(regEx);
//        Matcher m = p.matcher(str);
        return Pattern.matches(regEx, str);
    }
}
